/**
 * 验证 放用于验证的函数
*/

import menuSetting from '@/menuSet.js'
import Cookies from 'js-cookie'

const TokenKey = menuSetting.token || 'token'
export function getToken() {
  return Cookies.get(TokenKey)
}
export function setToken(token) {
  return Cookies.set(TokenKey, token)
}
export function removeToken() {
  return Cookies.remove(TokenKey)
}
/**
 * 是否是外部的链接
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}
export function getUserName() {
  return Cookies.get('userName')
}
export function setUserName(name) {
  return Cookies.set('userName', name)
}
export function removeUserName() {
  return Cookies.remove('userName')
}
export function getOutletName() {
  return Cookies.get('outletName')
}
export function setOutletName(name) {
  return Cookies.set('outletName', name)
}
export function removeOutletName() {
  return Cookies.remove('outletName')
}
export function getOutletId() {
  return Cookies.get('outletId')
}
export function setOutletId(id) {
  return Cookies.set('outletId', id)
}
export function removeOutletId() {
  return Cookies.remove('outletId')
}
export function getHomeRouter() {
  const obj = {
    path: '/index',
    name: '首页'
  }
  // return JSON.parse(Cookies.get('homeRouter')) || obj
  return Cookies.get('homeRouter') || obj
}
export function setHomeRouter(obj) {
  return Cookies.set('homeRouter', obj)
}
export function setAuthInfo(obj) {
  return Cookies.set('authInfo', obj)
}
export function getAuthInfo() {
  return Cookies.get('authInfo')
}
export function removeAuthInfo() {
  return Cookies.remove('authInfo')
}
/**
 * 是否是有效的权限
 * @param {string} str
 * @returns {Boolean}
 */
// function validUsername(str) {
//   const valid_map = ['admin', 'editor']
//   return valid_map.indexOf(str.trim()) >= 0
// }
